package com.yaorange.certificate.controller;

import java.util.List;

import com.yaorange.certificate.service.ISysPosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.yaorange.common.annotation.Log;
import com.yaorange.common.core.controller.BaseController;
import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.common.core.page.TableDataInfo;
import com.yaorange.common.enums.BusinessType;
import com.yaorange.certificate.domain.SysPos;

/**
 * 公告 信息操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/pos")
public class SysPosController extends BaseController {
    @Autowired
    private ISysPosService posService;

    /**
     * 获取一体机服务点列表
     */
    @PreAuthorize("@ss.hasPermi('system:pos:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPos pos) {
        startPage();
        List<SysPos> list = posService.selectPosList(pos);
        return getDataTable(list);
    }


    /**
     * 新增服务点
     */
    @PreAuthorize("@ss.hasPermi('system:pos:add')")
    @Log(title = "一体机服务点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysPos pos) {
        pos.setCreateBy(getUsername());
        return toAjax(posService.insertPos(pos));
    }


    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('t')")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(posService.selectPosById(id));
    }
    /**
     * 修改服务点
     */
    @PreAuthorize("@ss.hasPermi('system:pos:edit')")
    @Log(title = "一体机服务点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysPos pos) {
        pos.setUpdateBy(getUsername());
        return toAjax(posService.updatePos(pos));
    }


    /**
     * 删除服务点
     */
    @PreAuthorize("@ss.hasPermi('system:pos:remove')")
    @Log(title = "一体机服务点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids) {
        return toAjax(posService.deletePosByIds(ids));
    }
}
